package com.kkb.kkbportal.controller;

import com.kkb.kkbcommon.api.CommonPage;
import com.kkb.kkbcommon.api.CommonResult;
import com.kkb.kkbportal.domain.vo.DetailBaseInfoVo;
import com.kkb.kkbportal.domain.vo.DetailProductionVo;
import com.kkb.kkbportal.domain.vo.DetailScoreVo;
import com.kkb.kkbportal.service.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 名人堂前台接口
 *
 * @author shenyiqi
 */
@RestController
@Api(tags = "名人堂管理", value = "")
@RequestMapping("/fame")
public class FameController {

    @Autowired
    private FameService fameService;
    @Autowired
    private ScoreService scoreService;
    @Autowired
    private ProductionInfoService productionInfoService;
    @Autowired
    private UserLikeScoreService userLikeScoreService;

    @ApiModelProperty(value = "用户给评论点赞")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id/点赞人id", dataType = "Long"),
            @ApiImplicitParam(name = "scoreId", value = "评论id", dataType = "Long")
    })
    @PostMapping(value = "/like/{userId}/{scoreId}")
    public CommonResult<Boolean> scoreLike(@PathVariable("userId") Long userId,
                                           @PathVariable("scoreId") Long scoreId){
        Boolean liked = userLikeScoreService.like(userId, scoreId);
        if(liked){
            return CommonResult.success(true, "已点赞");
        }
        return CommonResult.success(false, "取消点赞");
    }

    /**
     * 根据导师/学员id，查询基本信息
     *
     * @param id 导师/学员id
     * @return 基本信息：基本个人资料、综合得分、完成项目数
     */
    @ApiOperation(value = "根据导师/学员id，查询基本信息", notes = "基本信息：基本个人资料、综合得分、完成项目数")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "导师/学员id", dataType = "Long")
    )
    @GetMapping(value = "/details/baseInfo/{id}")
    public CommonResult<DetailBaseInfoVo> baseInfo(@PathVariable("id") Long id) {

        // 1. FameService 查询基本个人资料
        DetailBaseInfoVo detailBaseInfoVo = fameService.selectBaseInfoById(id);

        // 2. 返回前端
        return CommonResult.success(detailBaseInfoVo, "查询成功");
    }

    /**
     * 根据导师/学员id，查询作品集
     *
     * @param id 导师/学员id
     * @return 作品集列表
     */
    @ApiOperation(value = "根据导师/学员id，查询作品集", notes = "作品集展示")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "导师/学员id", dataType = "Long")
    )
    @GetMapping("/details/productionInfoList/{id}")
    public CommonResult<List<DetailProductionVo>> productionList(@PathVariable("id") Long id) {
        // 1. productionInfoService查询列表
        List<DetailProductionVo> detailProductionVoList = productionInfoService.selectProductionListById(id);

        // 2. 返回前端
        return CommonResult.success(detailProductionVoList, "查询成功");
    }

    /**
     * 根据导师/学员id，展示评价列表
     *
     * @param id 导师/学员id
     * @return 评价列表
     */
    @ApiOperation(value = "根据导师/学员id，查询评价列表", notes = "评价列表展示")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "导师/学员id", dataType = "Long")
    )
    @GetMapping("/details/scoreList/{id}")
    public CommonResult<List<DetailScoreVo>> scoreList(@PathVariable("id") Long id) {
        // 1. scoreService查询列表
        List<DetailScoreVo> detailScoreVoList = scoreService.selectScoreDetailListBySlaveId(id);

        // 2. 返回前端
        return CommonResult.success(detailScoreVoList, "查询成功");
    }

    /**
     * 分页查询
     *
     * @param roleId   角色Id
     * @param pageNum  页码
     * @param pageSize 每页显示行数
     * @return
     */
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色Id", dataType = "Long"),
            @ApiImplicitParam(name = "pageNum", value = "当前页数", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", defaultValue = "10", dataType = "int")
    })
    @GetMapping("/page/{roleId}")
    public CommonResult<CommonPage<DetailBaseInfoVo>> listPage(@PathVariable("roleId") Long roleId,
                                                               @RequestParam(defaultValue = "1") Integer pageNum,
                                                               @RequestParam(defaultValue = "10") Integer pageSize) {
        return CommonResult.success(CommonPage.restPage(fameService.listPage(roleId, pageNum, pageSize)), "查询成功");
    }
}
